import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provide/provide.dart';
import '../../provide/cart_provide.dart';
import '../../model/cart_model.dart';

class CatFotter extends StatelessWidget {
  const CatFotter({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(5.0),
      color: Colors.white,
      child: Provide<CartProvide>(
        builder: (context,child,val){
          return Row(
              children: <Widget>[
                _selecAll(context),
                _allPrice(context),
                _goButton(context)
              ],
            );
          }
       ),
    );
  }

  Widget  _selecAll(context){
    bool isAllSelected = Provide.value<CartProvide>(context).isAllSelected;
    return Container(
      child: Row(
        children: <Widget>[
          Checkbox(
            value: isAllSelected,
            activeColor:Colors.pink,
            onChanged: (bool val){
                Provide.value<CartProvide>(context).changAllselectedBtn(val);
            },
          ),
          Text('全选')
        ],
      ),
    );
  }

  Widget _allPrice(context){
    double allProice = Provide.value<CartProvide>(context).allPrice;
    return Container(
      width: ScreenUtil().setWidth(430.0),
      child: Column(
        children: <Widget>[
          Row(
            children: <Widget>[
              Container(
                alignment: Alignment.centerRight,
                width: ScreenUtil().setWidth(280.0),
                child: Text('合计：',
                  style: TextStyle(
                    fontSize: ScreenUtil().setSp(36.0)
                  ),
                ),
              ),
              Container(
                alignment: Alignment.centerLeft,
                width: ScreenUtil().setWidth(150.0),
                child: Text(
                  '￥$allProice',
                  style:TextStyle(
                    fontSize:ScreenUtil().setSp(36),
                    color:Colors.pink
                  )
                ),
                )
            ],
          ),
          Container(
            width: ScreenUtil().setWidth(430),
            alignment: Alignment.centerRight,
            child: Text(
              '满10元免配送费，预购免配送费',
              style:TextStyle (
                  color: Colors.black38,
                  fontSize: ScreenUtil().setSp(22.0)
              )
            ),
          ),
        ],
      ),
    );
  }

  Widget _goButton(context){
    int allGoodsCount = Provide.value<CartProvide>(context).allGoodsCount;
    return Container(
      width: ScreenUtil().setWidth(160),
      padding: EdgeInsets.only(left: 10),
      child: InkWell(
        onTap: (){

        },
        child: Container(
          padding: EdgeInsets.all(10.0),
          alignment: Alignment.center,
          decoration: BoxDecoration(
            color: Colors.red,
            borderRadius: BorderRadius.circular(3.0),
          ),
          child: Text('结算(${allGoodsCount})',
            style: TextStyle(color: Colors.white),
          ),
        ),
      ),
    );
  }


}